package com.example.lin.controller;

import com.example.lin.common.R;
import com.example.lin.entity.pojo.Permission;
import com.example.lin.service.PermissionService;
import com.example.lin.utils.TreeUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lzh
 * @since 2024-12-15
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    @GetMapping(value = "/tree")
    public R tree() {
        List<Permission> list = permissionService.list();
        List<Permission> collect = TreeUtil.permissionTree(list, 0);
        return R.ok(collect);
    }
}
